//
//  YDProfileViewController.m
//  IngCard
//
//  Created by kf on 2017/6/1.
//  Copyright © 2017年 IngDan. All rights reserved.
//

#import "YDProfileViewController.h"
#import "YDBaseTableViewCell.h"
#import "YDPeripheralsViewController.h"
#import "YDMessageViewController.h"
#import "YDUserInfoTableViewCell.h"
#import "YDUserSettingTableViewCell.h"
#import "YDUserSettingViewController.h"
#import "YDAccountManager.h"
#import "YDUserBaseInfoEditViewController.h"
#import "YD3rdInfoConfirmViewController.h"
#import "MYInfoViewController.h"

typedef enum : NSUInteger {
    KMyBaseInfo = 1,
    kMyProfile,
    kSmartCard,
    kTimeLine,
    kMoreSetting,
} MyProfileEventID;



@interface YDProfileViewController ()<UINavigationControllerDelegate>

@end

@implementation YDProfileViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.delegate = self;
    self.automaticallyAdjustsScrollViewInsets = false;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//    self.tableView.backgroundColor = UIColorRed;
    self.tableView.contentInset = UIEdgeInsetsMake(-20, 0, 0, 0); 
}


-(void) initDataSource
{
    [super initDataSource];
    
    Weak(self);
    [self.dataSource addDataSource:[YDUserInfoCellDataSource class]
                         atSection:0
                            config:^(YDUserInfoCellDataSource* dataSource)
     {
         Log(@"%@",ACCOUNT.account);
         
         Strong(self);
         NSString *userName = NSStringFormat(@"%@%@",ACCOUNT.account.firstName,ACCOUNT.account.lastName);
         dataSource.name = userName?userName: @"待完善";
         dataSource.title = ACCOUNT.account.occupation ?ACCOUNT.account.occupation:@"待完善";
         dataSource.origination = ACCOUNT.account.company ?ACCOUNT.account.company:@"待完善";
         dataSource.tag = KMyBaseInfo;
         
         dataSource.editBlock = ^{
             YDUserBaseInfoEditViewController *vc = [[YDUserBaseInfoEditViewController alloc] init];         [self.navigationController pushViewController:vc animated:YES];
         };
     }];
    
    [self.dataSource addDataSource:[YDUserSettingCellDataSource class]
                         atSection:0
                            config:^(YDUserSettingCellDataSource* dataSource)
     {
         dataSource.title = @"个人资料";
         dataSource.tag = KMyBaseInfo;
     }];
    
    [self.dataSource addDataSource:[YDUserSettingCellDataSource class]
                         atSection:0
                            config:^(YDUserSettingCellDataSource* dataSource)
     {
         dataSource.title = @"账号设置";
         dataSource.tag = kMyProfile;
     }];
    
    
    [self.dataSource addDataSource:[YDUserSettingCellDataSource class]
                         atSection:0
                            config:^(YDUserSettingCellDataSource* dataSource)
     {
         dataSource.title = @"联系我们";
     }];
    
    
    [self.dataSource addDataSource:[YDUserSettingCellDataSource class]
                         atSection:0
                            config:^(YDUserSettingCellDataSource* dataSource)
     {
         dataSource.title = @"卡片管理";
     }];
    
    
    [self.dataSource addDataSource:[YDUserSettingCellDataSource class]
                         atSection:0
                            config:^(YDUserSettingCellDataSource* dataSource)
     {
         dataSource.title = @"分享名片";
     }];
}


- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [THEME renderStatusBarStyle:YDStatusBarStyle_Dark];
}

- (void) viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear: animated];
    
    [THEME renderStatusBarStyle:YDStatusBarStyle_Light];
}
// 将要显示控制器
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    // 判断要显示的控制器是否是自己
    BOOL isShowHomePage = [viewController isKindOfClass:[self class]];
    
    [self.navigationController setNavigationBarHidden:isShowHomePage animated:YES];
}


#pragma mark - <UITableViewDelegate>、<UITableViewDataSource>

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    YDBaseTableViewCellDataSrouce *dataSource = [self.dataSource dataSourceAtIndexPath:indexPath];
    
    switch (dataSource.tag) {
        case  kMyProfile:
        {
            YDUserSettingViewController *settingViewController = [[YDUserSettingViewController alloc] init];
            
            [self.navigationController pushViewController:settingViewController animated:YES];
        }
            break;
            
            
        case KMyBaseInfo:
        {
            MYInfoViewController *infoVC = [MYInfoViewController new];
            [self.navigationController pushViewController:infoVC animated:YES];
        }
            break;
        default:
            break;
    }
}

@end
